﻿using System;
using System.ComponentModel;
using Autodesk.Revit.DB;

namespace HYFamilyLibDataManager
{
	[DefaultProperty("Parameter")]
	public class DbParamDefinition
	{
		[Browsable(false)]
		public ParamDefinitionType ParamDefinitionType
		{
			get
			{
				return this.paramDefinitionType;
			}
			set
			{
				this.paramDefinitionType = value;
			}
		}

		[Category("属性")]
		[Description("参数名称")]
		[DisplayName("名称")]
		public string Name
		{
			get
			{
				return this.mName;
			}
		}

		[Category("属性")]
		[Description("参数别名")]
		[DisplayName("别名")]
		public string CustomName
		{
			get
			{
				return this.mCustomName;
			}
			set
			{
				this.mCustomName = value;
			}
		}

		[Category("属性")]
		[Description("参数显示单位-DisplayUnitType")]
		[DisplayName("显示单位")]
		[ReadOnly(true)]
		public DisplayUnitType DisplayUnitType
		{
			get
			{
				return this.displayUnitType;
			}
			set
			{
				this.displayUnitType = value;
			}
		}

		[Category("属性")]
		[Description("参数类型-ParameterType")]
		[DisplayName("类型")]
		[ReadOnly(true)]
		public ParameterType ParameterType
		{
			get
			{
				return this.parameterType;
			}
			set
			{
				this.parameterType = value;
			}
		}

		[Category("属性")]
		[Description("是否实例属性")]
		[DisplayName("实例属性")]
		[ReadOnly(true)]
		public bool IsInstance
		{
			get
			{
				return this.paramDefinitionType == ParamDefinitionType.InstanceParam;
			}
		}

		[Category("属性")]
		[Description("参数单位")]
		[DisplayName("单位")]
		public string Unit
		{
			get
			{
				return this.mUunit;
			}
			set
			{
				this.mUunit = value;
			}
		}

		[Browsable(false)]
		public StorageType StorageType
		{
			get
			{
				return this.mStorageType;
			}
			set
			{
				this.mStorageType = value;
			}
		}

		[Category("属性")]
		[Description("参数描述")]
		[DisplayName("描述")]
		public string Description
		{
			get
			{
				return this.mDescription;
			}
			set
			{
				this.mDescription = value;
			}
		}

		[Category("属性")]
		[Description("参数分组-BuiltInParameterGroup")]
		[DisplayName("分组")]
		[ReadOnly(true)]
		public BuiltInParameterGroup BuiltInParameterGroup
		{
			get
			{
				return this.builtInParameterGroup;
			}
			set
			{
				this.builtInParameterGroup = value;
			}
		}

		public DbParamDefinition(string pName, ParameterType pType, ParamDefinitionType pDefinitionType, BuiltInParameterGroup parameterGroup)
		{
			this.mName = pName;
			this.parameterType = 0;
			try
			{
				this.parameterType = pType;
			}
			catch
			{
			}
            this.builtInParameterGroup = (BuiltInParameterGroup)(-1);
			try
			{
				this.builtInParameterGroup = parameterGroup;
			}
			catch
			{
			}
			this.paramDefinitionType = pDefinitionType;
		}

		public override string ToString()
		{
			return this.mName;
		}

		[Browsable(false)]
		public bool Limit
		{
			get
			{
				return this.mLimit;
			}
			set
			{
				this.mLimit = value;
			}
		}

		[Browsable(false)]
		public int Order
		{
			get
			{
				return this.mOrder;
			}
		}

		public void SetOrder(int value)
		{
			this.mOrder = value;
		}

		public override bool Equals(object obj)
		{
			DbParamDefinition dbParamDefinition = obj as DbParamDefinition;
			return dbParamDefinition != null && this.mName.ToUpper() == dbParamDefinition.mName.ToUpper();
		}

		public override int GetHashCode()
		{
			return this.Name.GetHashCode();
		}

		private ParamDefinitionType paramDefinitionType;

		protected string mName;

		protected string mCustomName;

        protected DisplayUnitType displayUnitType = (DisplayUnitType)(-2);

        protected ParameterType parameterType = (ParameterType)(1);

		protected bool isInstance;

		protected string mUunit;

		protected StorageType mStorageType;

		protected string mDescription;

		private BuiltInParameterGroup builtInParameterGroup;

		public bool mLimit;

		public int mOrder;
	}
}
